﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DSS_XNA.Engine.Error;
using DSS_XNA.Engine.Script;
using DSS_XNA.Engine.System;

namespace DSS_XNA.Engine.Script.Functions
{
    public class ScriptFunction_GetSystemVariable
    {
        #region Static Methods

        public static object Action(List<string> args, ScriptManager manager, Game1 engine)
        {
            if (args.Count != 1)
                throw new DSSException("Incorrect number of arguments for Build In Function GetSystemVariable");

            string name = args[0].ToLower().Trim();

            object value = null;

            switch (name)
            {
                #region Development
                case "development_isdebugmode": value = Game1.IsDebugMode; break;
                case "development_showdeveloperwindow": value = engine.DeveloperWindow != null; break;
                #endregion
                #region Font
                case "font_name": value = engine.GameFontName; break;
                #endregion
                #region Misc
                case "window_title": value = engine.Window.Title; break;
                #endregion
                #region Physics
                case "physics_gravity": value = World.World.Gravity; break;
                #endregion
                #region Position
                case "screen_x": value = engine.GraphicsDevice.Viewport.X; break;
                case "screen_y": value = engine.GraphicsDevice.Viewport.Y; break;
                case "window_x": value = engine.Window.ClientBounds.X; break;
                case "window_y": value = engine.Window.ClientBounds.Y; break;
                #endregion
                #region Size
                case "screen_height_in_meters": value = engine.GraphicsDevice.Viewport.Height / World.World.Meter; break;
                case "screen_width_in_meters": value = engine.GraphicsDevice.Viewport.Width / World.World.Meter; break;
                case "screen_height_in_pixels": value = engine.GraphicsDevice.Viewport.Height; break;
                case "screen_width_in_pixels": value = engine.GraphicsDevice.Viewport.Width; break;
                case "size_meter": value = World.World.Meter; break;
                case "window_height_in_pixels": value = engine.Window.ClientBounds.Height; break;
                case "window_width_in_pixels": value = engine.Window.ClientBounds.Width; break;
                #endregion
                #region Time
                case "time_leveltime": value = engine.CurrentWorld.CurrentWorld.LevelTimer.Time.ToString(); break;
                case "time_leveltime_in_milliseconds": value = engine.CurrentWorld.CurrentWorld.LevelTimer.Time.TotalMilliseconds; break;
                #endregion
                #region World
                case "world_height_in_meters": value = engine.CurrentWorld.CurrentWorld.GetProperty("HeightInMeters"); break;
                case "world_width_in_meters": value = engine.CurrentWorld.CurrentWorld.GetProperty("WidthInMeters"); break;
                case "world_height_in_pixels": value = engine.CurrentWorld.CurrentWorld.GetProperty("HeightInPixels"); break;
                case "world_width_in_pixels": value = engine.CurrentWorld.CurrentWorld.GetProperty("WidthInPixels"); break;
                #endregion
                #region Menu
                case "menu_default_script_name": value = Globals.DefaultMenuScriptName; break;
                #endregion
                default: throw new DSSException(String.Format("Unknown System Variable: {0}", name));
            }

            return value;
        }

        #endregion
    }
}
